CREATE procedure amsp_ICPromote
@InSourceNodeID numeric
AS
BEGIN
Declare
@DestID numeric,
@SourceSortOrder numeric,
@SourceDepth numeric,
@SourceParentID numeric
BEGIN TRANSACTION
SELECT
@SourceSortOrder = SortOrder,
@SourceDepth = CategoryDepth,
@SourceParentID = ParentCategoryID
FROM
Interest_Category
WHERE
InterestCategoryID = @InSourceNodeID
IF @SourceDepth > 1 BEGIN
SELECT @DestID = ParentCategoryID
FROM Interest_Category
WHERE InterestCategoryID = @SourceParentID
IF @SourceDepth = 2 BEGIN
UPDATE Interest_Category
SET ParentCategoryID = NULL,
AncestorCategoryID = InterestCategoryID,
CategoryDepth = 1
WHERE InterestCategoryID = @InSourceNodeID
END
ELSE BEGIN
UPDATE Interest_Category
SET ParentCategoryID = @DestID
WHERE InterestCategoryID = @InSourceNodeID
END
EXEC amsp_ICFixTree
COMMIT TRANSACTION
END
END
GO
GRANT EXECUTE ON [dbo].[amsp_ICPromote] TO [IMIS]
GO